/*! ============================================================================
 * @file test.c 
 * @Synopsis  
 * @author DongKai
 * @version 1.0
 * @date 2010年02月02日
 *  Company: Beijing Feynman Software Technology Co., Ltd.
 */

#include "test.h"

struct {
    int m;
    struct {
        void (*func)(void);
        void (*func2)(int);
        int ii;
    } * memfunc;
}aa;

struct {
    int m;
    struct {
        void (*func)(void);
        void (*func2)(int);
        int ii;
    } * memfunc;

}bb;
//============================================

SUB_CLASS_DEFINE(level1, Cobject)
    MEMBER_FUNC_DECBEGIN(level1)
    void MEMBER_FUNC_DECLARE(level1, test1)
    MEMBER_FUNC_DECEND
SUB_CLASS_DEFEND(level1)

VIRTUAL_FUNC_REGBEGIN(level1, Cobject)
DESTRUCTOR_REGISTER(level1)
VIRTUAL_FUNC_REGEND
//{
//    printf("level1 new %p.\n", self);
//    return self;
//}
DESTRUCTOR_DEFINE(level1)
{
    printf("level1 delete %p.\n", self);
}

void MEMBER_FUNC_DEFINE(level1, test1)
{
    puts("level1::test1\n");
}

MEMBER_FUNC_REGBEGIN(level1)
MEMBER_FUNC_REGISTER(level1, test1)
MEMBER_FUNC_REGEND

//===============================================

SUB_CLASS_DEFINE(level2, level1)
    MEMBER_FUNC_DECBEGIN(level2)
    void MEMBER_FUNC_DECLARE(level2, test1)
//    void MEMBER_FUNC_DECLARE(level2, print, int b)
    MEMBER_FUNC_DECEND
SUB_CLASS_DEFEND(level2)

void MEMBER_FUNC_DEFINE(level2, print, int b)
{
    printf("level2::print=%d.\n", b);
}

DESTRUCTOR_DEFINE(level2)
{
    printf("level2 delete %p.\n", self);
}
void MEMBER_FUNC_DEFINE(level2, test1)
{
    puts("level2::test1\n");
}

VIRTUAL_FUNC_REGBEGIN(level2, level1)
DESTRUCTOR_REGISTER(level2)
VIRTUAL_FUNC_REGISTER(level2, print)
VIRTUAL_FUNC_REGEND

MEMBER_FUNC_REGBEGIN(level2)
MEMBER_FUNC_REGISTER(level2, test1)
MEMBER_FUNC_REGEND

//================================================

SUB_CLASS_DEFINE(level3, level2)
    MEMBER_FUNC_DECBEGIN(level3)
    CONSTRUCTOR_ARGS_DECLARE(level3, int, int)
    MEMBER_FUNC_DECEND
SUB_CLASS_DEFEND(level3)
VIRTUAL_FUNC_REGBEGIN(level3, level2)
DESTRUCTOR_REGISTER(level3)
VIRTUAL_FUNC_REGEND

CONSTRUCTOR_DEFINE(level3)
{
    printf("level3 New %p.\n", self);
    return self;
}

CONSTRUCTOR_ARGS_DEFINE(level3, int i3, int j3)
{
    CALL_MEMBER_FUNC(((Cobject*)self), Cobject_args, j3, i3);
    printf("level3 New %p. i3=%d, j3=%d\n", self, i3, j3);
    return self;
}
DESTRUCTOR_DEFINE(level3)
{
    printf("level3 delete %p.\n", self);
}
MEMBER_FUNC_REGBEGIN(level3)
MEMBER_FUNC_REGISTER(level3, level3)
MEMBER_FUNC_REGISTER(level3, level3_args)
MEMBER_FUNC_REGEND
//================================================

void MEMBER_FUNC_DEFINE(Cobject, test, int a, char b)
{
    puts("Hi, I'am Cobject_test.\n");
}

int main()
{
#if 1
    level3 *p = NEW(level3);
    Cobject *p2 = (Cobject *)p;
    printf("p=%p\n", p);
    CALL_MEMBER_FUNC(p2, test1);
    CALL_VIRTUAL_FUNC1(void, p, print, 11);
    DELETE(p);
#endif
#if 0
    level3 * ap = NEW_ARRAY(level3, 4);
    DELETE_ARRAY(ap, 4);
#endif
#if 0
    level3 * ap = NEW_ARRAY_ARGS(level3, 2, 11, 222);
    DELETE_ARRAY(ap, 2);
#endif

//    sub1 *s = NEW(sub1);
//    DELETE(s);
//    sub2 *ss = NEW(sub2);
//    dump_obj(ss);
//    TEST(ss);
//    printf("guse=%p\n", (*(vtable_t **)ss));
//    DELETE(ss);
    return 0;
}


